import { createRouter, createWebHistory } from 'vue-router';
import HelloWorld from '../components/HelloWorld.vue';
import UserManage from '../components/UserManage.vue';
import SupplierProjectList from '../components/SupplierProjectList.vue';
import ProjectSupplierDetail from '../components/ProjectSupplierDetail.vue';

const routes = [
  { 
    path: '/', 
    component: HelloWorld 
  },
  { 
    path: '/manage', 
    component: UserManage 
  },
  {
    path: '/supplier-project',
    name: 'SupplierProjectList',
    component: SupplierProjectList,
    meta: {
      title: '供应商项目管理'
    }
  },
  {
    path: '/project-supplier-detail/:id',
    name: 'ProjectSupplierDetail',
    component: ProjectSupplierDetail,
    props: true,
    meta: {
      title: '项目供应商详情'
    }
  }
];

const router = createRouter({
  history: createWebHistory(),
  routes
});

// 路由守卫 - 设置页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
});

export default router;